//
//  SZHomeTableViewController.m
//  Weibo
//
//  Created by Zahi on 2017/7/22.
//  Copyright © 2017年 Zahi. All rights reserved.
//

#import "SZHomeTableViewController.h"
#import "SZVisitorView.h"
#import "SZHomeVM.h"
#import "SZHomeStatusCell.h"
#import "SZStatus.h"

@interface SZHomeTableViewController ()

/**应用homeVC**/
@property (nonatomic, strong) SZHomeVM *homeVM;

@end

@implementation SZHomeTableViewController


#pragma mark  应用homeVM
- (SZHomeVM *)homeVM
{
    if (_homeVM == nil) {
        _homeVM = [SZHomeVM new];
    }
    return _homeVM;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (!self.isLogin) { //没有登录
        
        [self.visitorView setupVisitorInfo:nil imageName:nil isHome:YES];
        
    } else { // 登录成功
        
        [self setupTableView];
        
        [self loadData];
    }
    
}

#pragma mark - 设置table view
- (void)setupTableView
{
    // 注册cell
    [self.tableView registerClass:[SZHomeStatusCell class] forCellReuseIdentifier:HomeCellId];
    
    self.tableView.rowHeight = 200;
}

/// 加载微博首页数据
- (void)loadData {
    
    [self.homeVM loadData:^(BOOL isOK) {
        
        if (isOK) {
            
            [self.tableView reloadData];
        }
    }];
    
    
    
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.homeVM.statusList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SZHomeStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeCellId forIndexPath:indexPath];
    
    SZStatusVM *statusVM = self.homeVM.statusList[indexPath.row];
    
    cell.statusVM = statusVM;
    
    
    return cell;

}

@end
